import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义 Store
export const useWorkStore = defineStore(
  'work',
  () => {
    // 工作数据列表
    const workList = ref([])

    // 添加工作数据
    const addWorkData = (item) => {
      workList.value.push(item)
    }
    // 设置工作数据
    const setWorkList = (arr) => {
      workList.value = arr
    }
    // 设置工作数据
    const getWorkList = () => {
      return JSON.parse(JSON.stringify(workList.value))
    }
    const clear = () => {
      workList.value = []
    }

    return {
      workList,
      addWorkData,
      setWorkList,
      getWorkList,
      clear,
    }
  },
  {
    // 网页端配置
    // persist: true,
    // 小程序端配置
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          return uni.setStorageSync(key, value)
        },
      },
    },
  },
)
